
package com.base.dehong.util;

import android.content.Context;
import android.util.DisplayMetrics;

/**
 *  <p>类描述：获取设备屏幕长宽和密度比的工具类
 */
public class ScreenUtil {
    private static ScreenUtil sInstance;

    private static int mScreenWidth;

    private static int mScreenHeight;

    private static float mDensity;

    public static ScreenUtil getInstance() {
        if (sInstance == null) {
            sInstance = new ScreenUtil();
        }
        return sInstance;
    }
    
    /**
     * 初始化工作
     * 
     * @param context
     */
    public static int[] init(Context context) {
    	
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        mScreenWidth = dm.widthPixels;
        mScreenHeight = dm.heightPixels;
        mDensity = dm.density;
        
        return new int[]{mScreenWidth,mScreenHeight};
    }

    /**
     * 调用之前请确认是否调用 {@link #init(Context)}进行初始化
     * 
     * @return 屏幕的宽度
     */
    public int getScreenWidth() {
        return mScreenWidth;
    }

    /**
     * 调用之前请确认是否调用 {@link #init(Context)}进行初始化
     * 
     * @return 屏幕的高度
     */
    public int getScreenHeight() {
        return mScreenHeight;
    }

    public float getDensity() {
        return mDensity;
    }
}
